import {createRouter, createWebHashHistory} from "vue-router";

import Content from "@/components/Content";
import MusicList from "@/components/MusicList";
import SingerList from "@/components/Sidebar/SingerList";
import SongSheetList from "@/components/Sidebar/SongSheetList";

/*let originPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location, success, failure) {
    if (success && failure) {
        originPush.call(this, location, success, failure);
    } else {
        originPush.call(this, location, () => {
        }, () => {
        });
    }
}

let originReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function (location, success, failure) {
    if (success && failure) {
        originReplace.call(this, location, success, failure);
    } else {
        originReplace.call(this, location, () => {
        }, () => {
        });
    }
}*/

const routes = [
    {path: "/", redirect: "/home"},
    {
        name: "home",
        path: "/home",
        component: Content,
        meta: {isFooterShow: true},
        children: [
            {
                path: "news",
                component: Content,
                // 独享路由守卫
                /*beforeEnter: (to, from, next) => {
                    console.log(to, from);
                    if (localStorage.getItem("school") === "zzs")
                        next();
                }*/
            },

        ]
    },
    {
        name: "list",
        path: "/list",
        component: MusicList,
        meta: {
            // 此组件不需要被缓存
            keepAlive: false,
        },
        children: [
            {
                name: "local",
                path: "local",
                component: MusicList,
            },
            {
                name: "history",
                path: "history",
                component: MusicList,
            },
            {
                name: "collection",
                path: "collection",
                component: MusicList,
            },
            {
                name: "songSheet",
                path: "songSheet",
                component: MusicList,
            },
            {
                name: "singer",
                path: "singer",
                component: MusicList,
            },
        ]
    },
    {
        name: "songSheetList",
        path: "/songSheetList",
        component: SongSheetList,
    },
    {
        name: "singerList",
        path: "/singerList",
        component: SingerList,
    },
]


export const router = createRouter({
    history: createWebHashHistory(),
    routes: routes
})
